Error of the Median with different window length, summary

DW 2015.10.27

In this notebook I want to show, that the error of the median filter depends on the window length of the filter and wave number of the sine wave.


In [1]:
import numpy as np
import matplotlib.pyplot as plt
import sys
# Add a new path with needed .py files.
sys.path.insert(0, 'C:\Users\Dominik\Documents\GitRep\kt-2015-DSPHandsOn\MedianFilter\Python') 

import functions
import gitInformation

In [2]:
%matplotlib inline

In [3]:
gitInformation.printInformation()


Information about this notebook
============================================================
Date: 2015-11-10
Python Version: 2.7.10 |Anaconda 2.3.0 (64-bit)| (default, May 28 2015, 16:44:52) [MSC v.1500 64 bit (AMD64)]
Git directory: C:\Users\Dominik\Documents\GitRep\kt-2015-DSPHandsOn\.git
Current git SHA: 3d75389fd98bd111b1e723db4da574f17ba90e9b
Remotes: fork, origin, 
Current branch: master
fork remote URL: http://github.com/dowa4213/kt-2015-DSPHandsOn.git
origin remote URL: https://github.com/ktakagaki/kt-2015-DSPHandsOn.git

Visualization of the Error rate with different window lengths and a sine with wave number 5 (128 samples)


In [4]:
fig = plt.figure()
for y in range (0, 40):
    if y % 2 == 1:
        functions.ErrorPlotWindow(5, y)
        
plt.savefig('WLError.png')


As you can see, the error is higher when the window is bigger.

The error rate is the mean of the absolute of the red line. The red line is the difference between the sine wave and the median filtered wave. With a bigger window the difference between median filtered wave and sine wave gets bigger. Thus we can say that the error depends on the size of the window.


In [5]:
plt.figure(figsize=(30,20)) 
for x in range(1, 5):
    for y in range(1, 6):
        # Creates different subplots in one figure, with x and y.
        # the window length is calculate.
        plt.subplot(5, 5, x + (y-1)*4)
        windowLength = ((x-1)*2 + (y-1)*8)*8 +1
        functions.medianSinPlot(16, windowLength, 16*128,128*5+1,-128*5-1)
        plt.suptitle('Median filtered sine waves', fontsize = 48)
        plt.xlabel(("Window length (/2 pi) = " + str(windowLength/128.)), fontsize=18)


Visualization of the Error rate with different wave numbers and different window lengths


In [6]:
fig = plt.figure(figsize=(30,20))
for x in range(1, 5):
    for y in range(1, 6):
        for z in range(0,40):
            if z%2 ==1:
                plt.subplot(5, 5, x + (y-1)*4)
                wavenum = (x-1) + (y-1)*4
                functions.ErrorPlotWindow(wavenum, z)
                plt.suptitle(' Error of the Median filter with different wave numbers and window lengths',
                             fontsize = 40)
                plt.xlabel(("Wave number = " + str((x-1) + (y-1)*4)), fontsize = 18)


At the beginning you can see the error rises with a higher wave number. But at the end there are some unlikely curves. This is because of the low samples(128).

Visualization of the Error rate with different wave numbers and different window lengths(1024 samples)


In [7]:
fig = plt.figure(figsize=(30,20))
for x in range(1, 5):
    for y in range(1, 6):
        for z in range(0,160,3):
            if z%2 ==1:
                plt.subplot(5, 5, x + (y-1)*4)
                wavenum = (x-1) + (y-1)*4
                functions.ErrorPlotWindow( wavenum, z, 1024 )
                plt.suptitle(' Error of the Median filter with different wave numbers and window lengths ',
                             fontsize = 40)
                plt.xlabel(("Wave number = " + str((x-1) + (y-1)*4)), fontsize = 18)
plt.savefig('SumErrorWL')


With more samples we get much smoother and better curves. As already mentioned rises the error with a higher wave number and bigger window. At wave number 11 - 19 we can see that the error gets smaller when the window length is big.